'user strict'
var quitAndNotice = require('../../../../module/quitAndNotice.js');
var app = getApp();

function submitForm() {
    //是否提交表单，默认是
    var temp = 0;
    for (var i = 1; i < app.globalData.user_form.length; i++) {
        if (app.globalData.user_form[i].fill_item_nec == true) {
            if (app.globalData.user_form[i].fill_a == '' || app.globalData.user_form[i].fill_a == undefined || app.globalData.user_form[i].fill_a == false) {
                //如果有未填项则设置不提交表单
                temp = 1;
                wx.showModal({
                    title: '提示',
                    content: `第${i}项是必填项，请填写后再提交`,
                    showCancel: false,
                    confirmText: '我知道了',
                });
                break;
            }
        }
    }
    //允许提交
    if (temp == 0) {
        wx.request({
            url: 'https://wx.jingqi.ink/wxapp/form/insert_recruit',
            method: 'POST',
            data: app.globalData.user_form,
            success(res) {
                quitAndNotice(1000, '../../index/index', '报名表已提交');
            }
        });
    }
}

module.exports = submitForm;